home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: uu4news.netcom.com!zodiac!szh
- From: szh@zcon.com (Syed Zaeem Hosain)
- Subject: Re: HELP! File Pointers
- Message-ID: <1996Jan9.083549.27165@zcon.com>
- Sender: szh@zcon.com (Syed Zaeem Hosain)
- Nntp-Posting-Host: zodiac
- Reply-To: szh@zcon.com
- Organization: Z Consulting Group
- References: <4csr4c$fem@newsbf02.news.aol.com>
- Date: Tue, 9 Jan 1996 08:35:49 GMT
-
- In article <4csr4c$fem@newsbf02.news.aol.com>, roberino@aol.com (Roberino) writes:
- >I am currently trying to keep one file open while opening other
- >files one at a time using a separate file pointer. However, as
- >soon as I read a line from the second file, the first file pointer
- >somehow gets destroyed and set to some position in the newly
- >opened file. Has anyone else encountered this? And if so,
- >is there a solution? (i.e. A way to protect the first file pointer
- >from being overwritten.)
- >
- >Here are the steps I am performing:
- >
- >void main()
-
- Ah! You will see flames for this. Change it to "int main()" and
- and do a return at the end of the function.
-
- >{
- > FILE *File1;
- > FILE *File2;
- >
- > File1 = fopen("FILENAME", "r+");
- >
- > /* loop through lines in File1 using fgets() */
- >
- > if (Condition) /* just indicating some condition was met */
- > {
- > File2 = fopen("FILENAME2", "r+");
- >
- > fgets(Line, File2); <----- As soon as this occurs, File1 gets
- > wiped out. Why?
- > }
- >}
-
- Well, the most obvious possibility is that you are using the wrong
- parameters for fgets. It takes three parameters and is declared as
- follows (at least on my Sun system):
-
- char *fgets (char *s, int n, FILE *stream)
-
- So, you should:
-
- - make sure that "Line" is large enough for the lines you
- expect to read.
-
- - call "fgets" with the right parameters.
-
- I'd also suggect finding a better compiler - one that properly warns
- you about this error in the call.
-
- Z
-
-
-
- --
- -------------------------------------------------------------------------
- | Syed Zaeem Hosain P. O. Box 610097 (408) 441-7021 |
- | Z Consulting Group San Jose, CA 95161 szh@zcon.com |
- -------------------------------------------------------------------------
-